const express = require("express");
const router = express.Router();
const createDBconnect = require("../../db/createDBconnect.js")
router.get("/energy/electricity",(req,res) => {
    // console.log(req.query)
    try{
        let connect = createDBconnect();
        console.log(req.query);
        let sqlString = `select * from electricity_total where \`地区\` = '${req.query.city}' union select * from electricity_water where \`地区\`='${req.query.city}' union select * from electricity_fire where \`地区\` = '${req.query.city}'`;
        connect.query(sqlString,(err,result)=>{
            if(err){
                console.log(`SQL error: ${err}!`);
                res.status(400)
            }
            else{
                res.send({
                    total: result[0],
                    water: result[1],
                    fire: result[2],
                })
            }
        })
    }catch(err){
        console.error(err);
    }
})


module.exports = router;